class Solution {
public:
    vector<int> searchRange(vector<int>& nums, int target) 
    {

        vector<int> res(2, -1);

        if(nums.size() == 0)
            return res;
           
        int low = 0;
        int height = nums.size(); 
        int mid;

        while(low < height)
        {
            int mid = low + (height - low) / 2;

            if(nums[mid] == target)
                height = mid;
            else if(nums[mid] > target)
                height = mid;
            else low = mid + 1;
        }

        if(nums[low] == target)
            res[0] = low;
        else res[0] = -1;
            

        low = 0;
        height = nums.size();

        while(low < height)
        {
            int mid = low + (height - low) / 2;

            if(nums[mid] == target) 
                low = mid + 1;                    
            else if(nums[mid] > target)
                height = mid;
            else low = mid + 1;
        }

        if(nums[height - 1] == target && height != 0)
            res[1] = height - 1;

        return res;
    }
};
//二分法查找左右边界